/**
 * 扫描二维码并且解析
 */
var qb = localStorage.getItem("qb");
$("#qb").val(qb);
window.onbeforeunload = function(e) {
	localStorage.removeItem('qb');
}

function startCan() {
	mui.openWindow({
		createNew:false,// 打开并且刷新：true刷新，false不刷新
		show:{
			autoShow:true,
			aniShow:'fade-in',
		},
		url: 'qr3.html',
		id: 'qr3'
	});
}
var first = true;

function addMailList() {
	//$(".weui-btn").attr("disabled", false);
	var options = $("#line option:selected").val();
	var addMailListReqbody = {
		"type": 0,
		"coinId": options,
		"name": $("#userName").val().trim(),
		"address": $("#qb").val().trim()
	};
	if(first) {
		first = false;
		$.ajax({
			type: "POST",
			url: ip + "platform/user/addAddressBook.m",
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			data: addMailListReqbody,
			success: function(data) {
				if(data.statusCode == 0) {
					//$(".weui-btn").attr("disabled", true);
					$.toptip("添加联系人成功！", 'success');
					setTimeout(function(){
				        mui.openWindow({
							createNew: true, // 打开并且刷新：true刷新，false不刷新
							show: {
								autoShow: true,
								aniShow: 'fade-in'
							},
							url: 'mailList.html',
							id: 'mailList'
						});
				    },1000);
				} else if(data.statusCode == 1000) {
					loginError();
				} else {
					$.toptip(data.resultDesc, 'error');
					first = true;
				}
			}
		});
	}
}
//getCoinQbbList();

function getCoinQbbList() {
	$.ajax({
		type: "GET",
		url: ip + "platform/trade/getCoinQbbList.m",
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(data) {
			if(data.statusCode == 0) {
				var html = '';
				for(var i = 0; i < (data.result).length; i++) {
					html += '<option value="' +
						data.result[i].id + '">' +
						data.result[i].name +
						'</option>';
				}
				$("#line").append(html);
			} else if(data.statusCode == 1000) {
				loginError();
			} else {
				$.toptip(data.resultDesc, 'error');
			}
		}
	});
}
function getTransferAccounts() {
	var qb = localStorage.getItem("qb");
	if(qb) {
		$("#qb").val(qb);
	}
}
//XXX 临时解决二维码返回刷新问题
setInterval("getTransferAccounts()", 1000);